/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.Actions;

import controller.Forms.SearchEditEnterpriseForm;
import dao.EnterpriseDAO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Enterprise;
import model.Erro;
import model.User;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author Adriano
 */
public class SearchEnterpriseEditAction extends Action {

    @Override
    public ActionForward execute(ActionMapping mapping,
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        try {

            User u = (User) request.getSession().getAttribute("User");
            SearchEditEnterpriseForm sef = (SearchEditEnterpriseForm) form;
            if (sef.getTxtCnpj().isEmpty()) {
                return mapping.findForward("erroAlias");
            }
            Enterprise empresa = new Enterprise();
            empresa.setTxtCnpj(sef.getTxtCnpj());
            EnterpriseDAO cDao = new EnterpriseDAO();
            empresa = (Enterprise) cDao.find(empresa);

            cDao.closeDAO();
            request.getSession().setAttribute("EmpresaEdit", empresa);
            return mapping.findForward("ResultEditEnterpriseAlias");

        

    }
    catch (Exception e

    
        ) {
            System.err.println("BUSCAUSEEDITRACTION - " + e.getMessage());
        return mapping.findForward("erroAlias");
    }
}

}
